//
//  ADDNewShopViewController.m
//  YiBaoStore
//
//  Created by 吕清毅 on 2018/10/2.
//  Copyright © 2018年 小河. All rights reserved.
//

#import "ADDNewShopViewController.h"
#import <AFNetworking.h>
#import <MapKit/MapKit.h>
#import "MyhAddressPickerView.h"
#import "CreateAccountController.h"
#import "MapViewController.h"
#import "CheckShopViewController.h"

@interface ADDNewShopViewController ()<UINavigationControllerDelegate,UIImagePickerControllerDelegate,NSURLSessionDelegate>

@property (nonatomic, strong) UIScrollView *mainScroll;
@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, strong) NSDictionary *dataDict;
@property (nonatomic, strong) NSDictionary *style;
@property (nonatomic, strong) UITextField *nameTF;
@property (nonatomic, strong) UITextField *addressTF;
@property (nonatomic, strong) UITextField *ownNameTF;
@property (nonatomic, strong) UITextField *telTF;
@property (nonatomic, assign) NSInteger btnTag; //选中的按钮tag值
@property (nonatomic, copy) NSString *indexUrl;
@property (nonatomic, copy) NSString *iconImageUrl;//logo
@property (nonatomic, copy) NSString *shopImageUrl;//店铺实景图
@property (nonatomic, copy) NSString *shopImageUrl2;//
@property (nonatomic, copy) NSString *mainImageUrl;//
@property (nonatomic, copy) NSString *codeUrl;//二维码
@property (nonatomic, copy) NSString *licenseUrl;//营业执照
@property (nonatomic, copy) NSString *authUrl;//授权图片
@property (nonatomic, copy) NSString *idCardFront;//身份证正面
@property (nonatomic, copy) NSString *idCardBack;//身份证反面
@property (nonatomic, copy) NSString *province;
@property (nonatomic, copy) NSString *city;
@property (nonatomic, copy) NSString *district;
@property (nonatomic, copy) NSString *address;
@property (nonatomic, strong) UILabel *errorLab;
@property (nonatomic, assign) double latitude;
@property (nonatomic, assign) double longitude;
@property (nonatomic, copy) NSString *nowLocation;
@end

@implementation ADDNewShopViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
    self.bgNavView.hidden = YES;
}

//- (void)viewWillDisappear:(BOOL)animated
//{
//    [super viewWillDisappear:animated];
//    self.navigationController.navigationBar.hidden = NO;
//}

- (void)viewDidLoad {
    [super viewDidLoad];
    if (self.isFailure) {
        [self getData];
    }
    else
    {
        [self setNavi];
    }
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(TextFieldChange) name:UITextFieldTextDidChangeNotification object:nil];
}

- (void)getData
{
    [[HttpRequest currentHttpRequest]postPath:GetResgitInfo params:nil resultBlock:^(id Data, MsgModel *msgModel) {
        dispatch_async(dispatch_get_main_queue(), ^{
            self.dataDict = Data;
            [self setNavi]; 
        });
    }];
}

/*
- (void)getName
{
    //反向地理编码
    CLGeocoder *clGeoCoder = [[CLGeocoder alloc] init];
    CLLocation *cl = [[CLLocation alloc] initWithLatitude:[self.dataDict[@"latitude"]floatValue] longitude:[self.dataDict[@"longitude"]floatValue]];
    self.latitude = [self.dataDict[@"latitude"]doubleValue];
    self.longitude = [self.dataDict[@"longitude"]doubleValue];
    [clGeoCoder reverseGeocodeLocation:cl completionHandler: ^(NSArray *placemarks,NSError *error)
    {
        for (CLPlacemark *placeMark in placemarks)
        {
            NSDictionary *addressDic = placeMark.addressDictionary;
            NSString *state= [addressDic objectForKey:@"State"];
            NSString *city=[addressDic objectForKey:@"City"];
            NSString *subLocality=[addressDic objectForKey:@"SubLocality"];
            NSString *street=[addressDic objectForKey:@"Street"];
            //,addressDic[@"Name"]
            self.province = state;
            self.city = city;
            self.district = subLocality;
            self.nowLocation = [NSString stringWithFormat:@"%@%@%@%@",state,city,subLocality,street];
            if ([self.nowLocation rangeOfString:@"(null)"].location !=NSNotFound)
            {
                self.nowLocation=[self.nowLocation stringByReplacingOccurrencesOfString:@"(null)"withString:@""];
                self.address = self.nowLocation;
            }
            NSLog(@"所在城市====%@ %@ %@ %@", state, city, subLocality, street);
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2*NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [self setNavi];
            });
        }
    }];
}
*/
- (void)setNavi
{
    UIView *navi = [UIView new];
    if (@available(iOS 11.0, *)) {
        navi.frame = CGRectMake(0, TopStatusHeight_xs, SCREENWIDTH, TopBarHeight);
    } else {
        // Fallback on earlier versions
        navi.frame = CGRectMake(0, TopStatusHeight, SCREENWIDTH, TopBarHeight);
    }
    navi.backgroundColor = [UIColor clearColor];
    [self.view addSubview:navi];
    
    UILabel *titleLab = [UILabel new];
    titleLab.frame = CGRectMake(0, 30, SCREENWIDTH, 18);
    titleLab.text = @"维护店铺";
    titleLab.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:18];
    titleLab.textAlignment = NSTextAlignmentCenter;
    titleLab.textColor = UIColorFromHex(0x343434);
    [navi addSubview:titleLab];
    
    self.mainScroll = [UIScrollView new];
    self.mainScroll.frame = CGRectMake(0, navi.bottom, SCREENWIDTH, SCREENHEIGHT-navi.bottom);
    self.mainScroll.backgroundColor = ClearColor;
    self.mainScroll.contentSize = CGSizeMake(SCREENHEIGHT, 2*SCREENHEIGHT);
    [self.view addSubview:self.mainScroll];
    
    UILabel *headLab = [UILabel new];
    headLab.frame = CGRectMake(2*leftPadding, 15, 120, 30);
    headLab.textColor = titleColor;
    headLab.font = FontSemiboldSize(22);
    headLab.attributedText = [TTKUtil getAtttributeStringWithLineSpace:0 kern:2 and:@"店铺信息"];
    [self.mainScroll addSubview:headLab];    
    
    //审核错误的提示
    UILabel *errorLab = [UILabel new];
    errorLab.frame = CGRectMake(40, headLab.bottom+15, SCREENWIDTH-80, 10);
    errorLab.textColor = UIColorFromHex(0xD0021B);
    errorLab.font = FontWithSize(10);
    errorLab.hidden = !self.isFailure;
    errorLab.text = self.dataDict[@"rejectMessage"];
    self.errorLab = errorLab;
    [self.mainScroll addSubview:errorLab];
    
    UILabel *avaLab = [UILabel new];
    avaLab.frame = CGRectMake(headLab.left, headLab.bottom+40, 52, 12);
    [self setLabelAttri:avaLab andStr:@"店铺头像"];
    [self.mainScroll addSubview:avaLab];
    
    UIImageView *avaView = [UIImageView new];
    avaView.frame = CGRectMake(avaLab.left, avaLab.bottom+12, 60, 60);
    avaView.backgroundColor = UIColorFromHex(0xf8f8f8);
    avaView.tag = 32;
    avaView.userInteractionEnabled = YES;
    [self.mainScroll addSubview:avaView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(shopPhoto:)];
    [avaView addGestureRecognizer:tap];
    
    CGFloat top = (60-26)/2;
    UIButton *avabtn = [UIButton buttonWithType:UIButtonTypeCustom];
    avabtn.frame = CGRectMake(top, top, 26, 26);
    [avabtn setBackgroundImage:[UIImage imageNamed:@"avatar"] forState:UIControlStateNormal];
    avabtn.tag = 33;
    avabtn.userInteractionEnabled = NO;
    [avaView addSubview:avabtn];
    if (self.isFailure) {
        self.iconImageUrl = self.dataDict[@"logo"];
        [avabtn setBackgroundImage:nil forState:UIControlStateNormal];
        [avaView sd_setImageWithURL:[NSURL URLWithString:self.dataDict[@"logo"]]placeholderImage:[UIImage imageNamed:@"Placeholder100"]];
    }
    
    
    //店铺名称
    UILabel *nameLab = [UILabel new];
    nameLab.frame = CGRectMake(avaLab.left, avaView.bottom+23, 52, 12);
    [self setLabelAttri:nameLab andStr:@"店铺名称"];
    [self.mainScroll addSubview:nameLab];
    
    UILabel *desLab = [UILabel new];
    desLab.frame = CGRectMake(SCREENWIDTH-40-71, nameLab.bottom+18, 71, 10);
    desLab.textColor = UIColorFromHex(0x828282);
    desLab.font = FontWithSize(10);
    desLab.text = @"限制在15字以内";
    desLab.textAlignment = NSTextAlignmentRight;
    [self.mainScroll addSubview:desLab];
    
    self.nameTF = [UITextField new];
    self.nameTF.frame = CGRectMake(nameLab.left, nameLab.bottom+13, SCREENWIDTH-40-desLab.width-40, 15);
    self.nameTF.textColor = titleColor;
    self.nameTF.font = FontWithSize(15);
    if (self.isFailure) {
        self.nameTF.text = [NSString stringWithFormat:@"%@",self.dataDict[@"shopName"]];
    }
    [self.mainScroll addSubview:self.nameTF];
    
    UIView *nameLine = [UIView new];
    nameLine.frame = CGRectMake(nameLab.left, self.nameTF.bottom+4, SCREENWIDTH-80, 1);
    nameLine.backgroundColor = UIColorFromHex(0xE3E3E3);
    [self.mainScroll addSubview:nameLine];
    
    UILabel *nameDesLab = [UILabel new];
    nameDesLab.frame = CGRectMake(nameLine.left, nameLine.bottom+5, 120, 10);
    nameDesLab.font = FontWithSize(10);
    nameDesLab.textColor = UIColorFromHex(0x828282);
    nameDesLab.text = @"* 如：文三路异宝店";
    [self.mainScroll addSubview:nameDesLab];
    
    //店主姓名
    UILabel *ownLab = [UILabel new];
    ownLab.frame = CGRectMake(nameLab.left, nameDesLab.bottom+30, 60, 12);
    [self setLabelAttri:ownLab andStr:@"店主姓名"];
    [self.mainScroll addSubview:ownLab];
    
    self.ownNameTF = [UITextField new];
    self.ownNameTF.frame = CGRectMake(nameLab.left, ownLab.bottom+13, SCREENWIDTH-40-40, 15);
    if (self.isFailure) {
        self.ownNameTF.text = [NSString stringWithFormat:@"%@",self.dataDict[@"ownerName"]];
    }
    self.ownNameTF.textColor = titleColor;
    self.ownNameTF.font = FontWithSize(15);
    [self.mainScroll addSubview:self.ownNameTF];
    
    UIView *ownLine = [UIView new];
    ownLine.frame = CGRectMake(nameLab.left, self.ownNameTF.bottom+4, SCREENWIDTH-80, 1);
    ownLine.backgroundColor = UIColorFromHex(0xE3E3E3);
    [self.mainScroll addSubview:ownLine];
    
    UILabel *ownDesLab = [UILabel new];
    ownDesLab.frame = CGRectMake(nameLine.left, ownLine.bottom+5, 120, 10);
    ownDesLab.font = FontWithSize(10);
    ownDesLab.textColor = UIColorFromHex(0x828282);
    ownDesLab.text = @"* 请输入您的姓名";
    [self.mainScroll addSubview:ownDesLab];
    
    //地址
    UILabel *addLab = [UILabel new];
    addLab.frame = CGRectMake(nameLab.left, ownDesLab.bottom+30, 52, 12);
    [self setLabelAttri:addLab andStr:@"地址"];
    [self.mainScroll addSubview:addLab];
    
    self.addressTF = [UITextField new];
    self.addressTF.frame = CGRectMake(nameLab.left, addLab.bottom+13, SCREENWIDTH-80, 15);
    self.addressTF.textColor = titleColor;
    self.addressTF.font = FontWithSize(15);
    
    if (self.isFailure) {
        self.latitude = [self.dataDict[@"latitude"]doubleValue];
        self.longitude = [self.dataDict[@"longitude"]doubleValue];
        self.province = [NSString stringWithFormat:@"%@",self.dataDict[@"province"]];
        self.city = [NSString stringWithFormat:@"%@",self.dataDict[@"city"]];
        self.district = [NSString stringWithFormat:@"%@",self.dataDict[@"district"]];
        self.address = [NSString stringWithFormat:@"%@",self.dataDict[@"address"]];
        self.addressTF.text = [NSString stringWithFormat:@"%@",self.address];
    }
    [self.mainScroll addSubview:self.addressTF];
    
    UIButton *addBtn = [UIButton buttonWithType: UIButtonTypeCustom];
    addBtn.frame = CGRectMake(self.addressTF.left,self.addressTF.top-8, SCREENWIDTH-80, 25);
    addBtn.backgroundColor = [UIColor clearColor];
    [addBtn addTarget:self action:@selector(getLocation) forControlEvents:UIControlEventTouchUpInside];
    [self.mainScroll addSubview:addBtn];
    
    UIImageView *addIV = [UIImageView new];
    addIV.frame = CGRectMake(self.addressTF.width-12, 0, 12, 14);
    addIV.image = [UIImage imageNamed:@"shopAddress"];
    [self.addressTF addSubview:addIV];
    
    UIView *addressLine = [UIView new];
    addressLine.frame = CGRectMake(nameLab.left, self.addressTF.bottom+4, SCREENWIDTH-80, 1);
    addressLine.backgroundColor = UIColorFromHex(0xE3E3E3);
    [self.mainScroll addSubview:addressLine];
    
    UILabel *addressDesLab = [UILabel new];
    addressDesLab.frame = CGRectMake(nameLine.left, addressLine.bottom+5, 120, 10);
    addressDesLab.font = FontWithSize(10);
    addressDesLab.textColor = UIColorFromHex(0x828282);
    addressDesLab.text = @"* 点击选择地址";
    [self.mainScroll addSubview:addressDesLab];
    
    //联系电话
    UILabel *telLab = [UILabel new];
    telLab.frame = CGRectMake(nameLab.left, addressDesLab.bottom+30, 52, 12);
    [self setLabelAttri:telLab andStr:@"联系电话"];
    [self.mainScroll addSubview:telLab];
    
    self.telTF = [UITextField new];
    self.telTF.frame = CGRectMake(nameLab.left, telLab.bottom+13, SCREENWIDTH-80, 15);
    if (self.isFailure) {
        self.telTF.text = self.dataDict[@"ownerMobile"];
    }
    self.telTF.textColor = titleColor;
    self.telTF.font = FontWithSize(15);
    [self.mainScroll addSubview:self.telTF];
    
    UIView *telLine = [UIView new];
    telLine.frame = CGRectMake(nameLab.left, self.telTF.bottom+4, SCREENWIDTH-80, 1);
    telLine.backgroundColor = UIColorFromHex(0xE3E3E3);
    [self.mainScroll addSubview:telLine];
    
    UILabel *telDesLab = [UILabel new];
    telDesLab.frame = CGRectMake(nameLine.left, telLine.bottom+5, 120, 10);
    telDesLab.font = FontWithSize(10);
    telDesLab.textColor = UIColorFromHex(0x828282);
    telDesLab.text = @"* 如：138xxxx3273";
    [self.mainScroll addSubview:telDesLab];
    
    //店铺实景图
    UILabel *shopRealLab = [UILabel new];
    shopRealLab.frame = CGRectMake(telLab.left, telDesLab.bottom+30, 120, 12);
    [self setLabelAttri:shopRealLab andStr:@"店铺实景图"];
    [self.mainScroll addSubview:shopRealLab];
    
    //上传图片
    NSArray *imageArray = self.dataDict[@"shopImage"];
    float realWidth = 60;
    for (int i = 0; i<2; i++) {
        UIImageView *shopRealIV = [UIImageView new];
        shopRealIV.frame = CGRectMake(40+75*i, shopRealLab.bottom+12, realWidth, realWidth);
        shopRealIV.backgroundColor = UIColorFromHex(0xF8F8F8);
        shopRealIV.tag = 60+i;
        shopRealIV.userInteractionEnabled = YES;
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(0, 0, shopRealIV.width, shopRealIV.height);
        btn.backgroundColor = ClearColor;
        btn.tag = 70+i;
        [btn addTarget:self action:@selector(shopRealImage:) forControlEvents:UIControlEventTouchUpInside];
        [shopRealIV addSubview:btn];
        
        UIImageView *addIV = [UIImageView new];
        addIV.frame = CGRectMake((60-23)/2, (60-22)/2, 23, 22);
        addIV.image = [UIImage imageNamed:@"shopTakePhoto"];
        addIV.tag = 65+i;
        [shopRealIV addSubview:addIV];
        
        UIImageView *deleteIV = [UIImageView new];
        deleteIV.frame = CGRectMake(shopRealIV.width-18, 0, 18, 18);
        deleteIV.tag = 72+i;
        deleteIV.userInteractionEnabled = YES;
        deleteIV.hidden = YES;
        deleteIV.image = [UIImage imageNamed:@"shopDelete"];
        if(i == 1) {
            shopRealIV.hidden = YES;
        }
        UIButton *deleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        deleBtn.frame = CGRectMake(0, 0, 18, 18);;
        deleBtn.tag = 74+i;
        deleBtn.hidden = YES;
        deleBtn.backgroundColor = [UIColor clearColor];
        [deleBtn addTarget:self action:@selector(deleteImage:) forControlEvents:UIControlEventTouchUpInside];
        [deleteIV addSubview:deleBtn];
        [shopRealIV addSubview:deleteIV];
        //[self.mainScroll insertSubview:deleteIV atIndex:0];
        if (self.isFailure) {
            if (imageArray.count==1) {
                shopRealIV.hidden = NO;
                self.shopImageUrl = [NSString stringWithFormat:@"%@",imageArray[0]];
                addIV.hidden = i == 0?YES:NO;
                deleteIV.hidden = i == 0?NO:YES;
                deleBtn.hidden = i == 0?NO:YES;
                if (i == 0) {
                     [shopRealIV sd_setImageWithURL:[NSURL URLWithString:imageArray[0]] placeholderImage:[UIImage imageNamed:@"Placeholder100"]];
                }
            }else
            {
                self.shopImageUrl = [NSString stringWithFormat:@"%@",imageArray[0]];
                self.shopImageUrl2 = [NSString stringWithFormat:@"%@",imageArray[1]];
                addIV.hidden = YES;
                deleteIV.hidden = NO;
                deleBtn.hidden = NO;
                shopRealIV.hidden = NO;
                [shopRealIV sd_setImageWithURL:[NSURL URLWithString:imageArray[i]] placeholderImage:[UIImage imageNamed:@"Placeholder100"]];
            }
        }
        [self.mainScroll addSubview:shopRealIV];
    }
    
    UILabel *realDesLab = [UILabel new];
    realDesLab.frame = CGRectMake(telLab.left, shopRealLab.bottom+72+5, 120, 10);
    realDesLab.font = FontWithSize(10);
    realDesLab.textColor = UIColorFromHex(0x828282);
    realDesLab.text = @"* 请上传两张店铺实景图";
    [self.mainScroll addSubview:realDesLab];
    
    //店主二维码
    UILabel *codeLabel = [UILabel new];
    codeLabel.frame = CGRectMake(telLab.left, realDesLab.bottom+20, 120, 12);
    [self setLabelAttri:codeLabel andStr:@"店铺微信二维码"];
    [self.mainScroll addSubview:codeLabel];
    [self setImageAndDes:@"shopCode" and:@"* 请上传一张店铺微信二维码" and:codeLabel and:90];
    
    //营业执照
    UILabel *licenseLab = [UILabel new];
    licenseLab.frame = CGRectMake(telLab.left, codeLabel.bottom+107, 120, 12);
    [self setLabelAttri:licenseLab andStr:@"营业执照照片"];
    [self.mainScroll addSubview:licenseLab];
    [self setImageAndDes:@"shopImage" and:@"* 请上传一张营业执照照片" and:licenseLab and:100];
   
    CGFloat calBottom = licenseLab.bottom + 87;
    
    //新加的功能
    UIImageView *newIV = [UIImageView new];
    newIV.frame = CGRectMake(15, calBottom+30, SCREENWIDTH-30, 350);
    newIV.image = [UIImage imageNamed:@"Rectangle"];
    newIV.userInteractionEnabled = YES;
    [self.mainScroll addSubview:newIV];
    
    UILabel *authLab = [UILabel new];
    authLab.frame = CGRectMake(8, 18, newIV.width-16, 30);
    authLab.numberOfLines = 2;
    authLab.textColor = UIColorFromHex(0x666666);
    authLab.font = FontWithSize(10);
    authLab.text = @"如果您上传的营业执照上法人姓名和收款人姓名不一致，请下载授权书， 按照要求填写后和身份证正反面一起上传。";
    [newIV addSubview:authLab];
    
    UIButton *downLoadBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    float downLoadPadding = (newIV.width-90)/2;
    downLoadBtn.frame = CGRectMake(downLoadPadding, authLab.bottom+20, 90, 18);
    [downLoadBtn setTitleColor:UIColorFromHex(0x4A90E2) forState:UIControlStateNormal];
    [downLoadBtn setTitle:@"下载授权书" forState:UIControlStateNormal];
    downLoadBtn.titleLabel.font = FontWithSize(18);
    [downLoadBtn addTarget:self action:@selector(download:) forControlEvents:UIControlEventTouchUpInside];
    [newIV addSubview:downLoadBtn];
    
    //上传授权书
    UILabel *uploadAuth = [UILabel new];
    uploadAuth.frame = CGRectMake(telLab.left, downLoadBtn.bottom+20, 180, 12);
    [self setLabelAttri:uploadAuth andStr:@"上传授权书（非必填）"];
    [newIV addSubview:uploadAuth];
    //[self setImageAndDes:@"shopImage" and:@"* 请上传授权书" and:uploadAuth and:110];
    UIImageView *shopRealIV = [UIImageView new];
    shopRealIV.frame = CGRectMake(40, uploadAuth.bottom+12, 60, 60);
    shopRealIV.tag = 110;
    if (self.isFailure&&![TTKUtil isNil:self.dataDict[@"authImage"]]) {
        self.authUrl = self.dataDict[@"authImage"];
        [shopRealIV sd_setImageWithURL:[NSURL URLWithString:self.dataDict[@"authImage"]]placeholderImage:[UIImage imageNamed:@"Placeholder100"]];
    }
    shopRealIV.backgroundColor = UIColorFromHex(0xF8F8F8);
    shopRealIV.userInteractionEnabled = YES;
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, shopRealIV.width, shopRealIV.height);
    btn.backgroundColor = ClearColor;
    btn.tag = 110+1;
    [btn addTarget:self action:@selector(shopImage:) forControlEvents:UIControlEventTouchUpInside];
    [shopRealIV addSubview:btn];
    
    UIImageView *aIV = [UIImageView new];
    aIV.frame = CGRectMake((60-23)/2, (60-22)/2, 23, 22);
    aIV.image = [UIImage imageNamed:@"shopImage"];
    aIV.tag = 110+2;
    [shopRealIV addSubview:aIV];
    [newIV addSubview:shopRealIV];
    
    UILabel *resLab = [UILabel new];
    resLab.frame = CGRectMake(shopRealIV.left, shopRealIV.bottom+5, 250, 10);
    resLab.font = FontWithSize(10);
    resLab.textColor = UIColorFromHex(0x828282);
    resLab.text = @"* 请上传授权书";
    [newIV addSubview:resLab];
    
    //上传营业执照身份证
    UILabel *bottomLab = [UILabel new];
    bottomLab.frame = CGRectMake(telLab.left, resLab.bottom+20, 180, 12);
    [self setLabelAttri:bottomLab andStr:@"上传营业执照法人身份证正反面（非必填)"];
    [newIV addSubview:bottomLab];
    
    //上传图片
    float idWidth = 86;
    float idHeight = 54;
    NSArray *idCardImageArray = self.dataDict[@"authIdCardImage"];
    for (int i = 0; i<2; i++) {
        UIImageView *shopRealIV = [UIImageView new];
        shopRealIV.frame = CGRectMake(40+96*i, bottomLab.bottom+12, idWidth, idHeight);
        shopRealIV.backgroundColor = UIColorFromHex(0xF8F8F8);
        shopRealIV.tag = 160+i;
        shopRealIV.userInteractionEnabled = YES;
        UIButton *idBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        idBtn.frame = CGRectMake(0, 0, shopRealIV.width, shopRealIV.height);
        idBtn.backgroundColor = ClearColor;
        idBtn.tag = 170+i;
        [idBtn addTarget:self action:@selector(shopIDCardImage:) forControlEvents:UIControlEventTouchUpInside];
        [shopRealIV addSubview:idBtn];
        
        UIImageView *addIV = [UIImageView new];
        addIV.frame = CGRectMake((idWidth-30)/2, 5, 26, 26);
        addIV.image = [UIImage imageNamed:@"shopImage"];
        addIV.tag = 165+i;
        [shopRealIV addSubview:addIV];
        
        UILabel *idLab = [UILabel new];
        idLab.frame = CGRectMake(0, addIV.bottom+5, idWidth, 10);
        idLab.textColor = UIColorFromHex(0x828282);
        idLab.font = FontWithSize(10);
        idLab.tag = 167+i;
        idLab.text = i == 0?@"身份证正面":@"身份证反面";
        idLab.textAlignment = NSTextAlignmentCenter;
        [shopRealIV addSubview:idLab];
        
        UIImageView *deleteIV = [UIImageView new];
        deleteIV.frame = CGRectMake(shopRealIV.width-18, 0, 18, 18);
        deleteIV.tag = 172+i;
        deleteIV.userInteractionEnabled = YES;
        deleteIV.hidden = YES;
        deleteIV.image = [UIImage imageNamed:@"shopDelete"];
        if (i == 1) {
            shopRealIV.hidden = YES;
        }
        UIButton *deleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        deleBtn.frame = CGRectMake(0, 0, 18, 18);;
        deleBtn.tag = 174+i;
        deleBtn.hidden = YES;
        deleBtn.backgroundColor = [UIColor clearColor];
        [deleBtn addTarget:self action:@selector(deleteIDCardImage:) forControlEvents:UIControlEventTouchUpInside];
        [deleteIV addSubview:deleBtn];
        [shopRealIV addSubview:deleteIV];
        //[self.mainScroll insertSubview:deleteIV atIndex:0];
        [newIV addSubview:shopRealIV];
        if (self.isFailure) {
            if (idCardImageArray.count==2) {
                addIV.hidden = YES;
                deleteIV.hidden = NO;
                deleBtn.hidden = NO;
                idLab.hidden = YES;
                self.idCardFront = idCardImageArray[0];
                self.idCardBack = idCardImageArray[1];
                [shopRealIV sd_setImageWithURL:[NSURL URLWithString:i==0?idCardImageArray[0]:idCardImageArray[1]] placeholderImage:[UIImage imageNamed:@"Placeholder100"]];
            }
        }
    }
    UILabel *bottom = [UILabel new];
    bottom.frame = CGRectMake(telLab.left, bottomLab.bottom+72+5, 120, 10);
    bottom.font = FontWithSize(10);
    bottom.textColor = UIColorFromHex(0x828282);
    bottom.text = @"* 请上传身份证正反面";
    [newIV addSubview:bottom];
    
    
    UIButton * nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    nextBtn.frame = CGRectMake(licenseLab.left, newIV.bottom+40, SCREENWIDTH-80, 50);
//    nextBtn.userInteractionEnabled = NO;
//    nextBtn.backgroundColor = UIColorFromHex(0xD1D1D1);
//    [nextBtn setTitleColor:UIColorFromHex(0x8D8D8D) forState:UIControlStateNormal];
    [nextBtn setAttributedTitle:[TTKUtil getAtttributeStringWithLineSpace:0 kern:1.5 and:@"下一步"] forState:UIControlStateNormal];
    nextBtn.layer.cornerRadius = 20;
    nextBtn.layer.masksToBounds = YES;
    nextBtn.backgroundColor = goldColor;
    [nextBtn setTitleColor:titleColor forState:UIControlStateNormal];
    [nextBtn addTarget:self action:@selector(nextBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.mainScroll addSubview:nextBtn];
    self.mainScroll.contentSize = CGSizeMake(SCREENWIDTH, nextBtn.bottom+50);
}

#pragma mark -- 跳转定位界面
- (void)getLocation
{
    MapViewController *mapVC = [MapViewController new];
    mapVC.callBack = ^(NSString * _Nonnull location, NSString * _Nonnull province, NSString * _Nonnull city, NSString * _Nonnull district, NSString * _Nonnull address, double latitude, double longitude)
    {
        self.addressTF.text = location;
        self.province = province;
        self.city = city;
        self.district = district;
        self.address = location;
        self.latitude = latitude;
        self.longitude = longitude;
    };
    [self.navigationController pushViewController:mapVC animated:YES];
}

#pragma mark -- 图片加描述
- (void)setImageAndDes:(NSString *)imageName and:(NSString *)desTitle and:(UILabel *)lab and:(NSInteger)imageTag
{
    UIImageView *shopRealIV = [UIImageView new];
    shopRealIV.frame = CGRectMake(40, lab.bottom+12, 60, 60);
    shopRealIV.tag = imageTag;
    shopRealIV.backgroundColor = UIColorFromHex(0xF8F8F8);
    shopRealIV.userInteractionEnabled = YES;
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, shopRealIV.width, shopRealIV.height);
    btn.backgroundColor = ClearColor;
    btn.tag = imageTag+1;
    [btn addTarget:self action:@selector(shopImage:) forControlEvents:UIControlEventTouchUpInside];
    [shopRealIV addSubview:btn];
    
    UIImageView *addIV = [UIImageView new];
    addIV.frame = CGRectMake((60-23)/2, (60-22)/2, 23, 22);
    addIV.image = [UIImage imageNamed:imageName];
    addIV.tag = imageTag+2;
    [shopRealIV addSubview:addIV];
    [self.mainScroll addSubview:shopRealIV];
    
    UILabel *realDesLab = [UILabel new];
    realDesLab.frame = CGRectMake(shopRealIV.left, shopRealIV.bottom+5, 250, 10);
    realDesLab.font = FontWithSize(10);
    realDesLab.textColor = UIColorFromHex(0x828282);
    realDesLab.text = desTitle;
    [self.mainScroll addSubview:realDesLab];
    if (self.isFailure&&imageTag==90) {
        addIV.hidden = YES;
        self.codeUrl = self.dataDict[@"sellerWechatQrImage"];
        [shopRealIV sd_setImageWithURL:[NSURL URLWithString:self.dataDict[@"sellerWechatQrImage"]] placeholderImage:[UIImage imageNamed:@"Placeholder100"]];
    }else if (self.isFailure&&imageTag==100)
    {
        addIV.hidden = YES;
        self.licenseUrl = self.dataDict[@"licenseImage"];
        [shopRealIV sd_setImageWithURL:[NSURL URLWithString:self.dataDict[@"licenseImage"]] placeholderImage:[UIImage imageNamed:@"Placeholder100"]];
    }
}

- (void)shopImage:(UIButton *)btn
{
    __weak __typeof(self) weakSelf = self;
    if (btn.tag == 91) {
        UIImageView *iv = (UIImageView *)[self.view viewWithTag:90];
        UIImageView *addIV = (UIImageView *)[self.view viewWithTag:92];
         [self takePhoto];
        self.photoBlock = ^(UIImage * _Nonnull image) {
            dispatch_async(dispatch_get_main_queue(), ^{
                addIV.hidden = YES;
                iv.image = image;
                weakSelf.codeUrl = [weakSelf uploadImageCodeUrl:image];
            });
        };
    }
    else if (btn.tag == 101)
    {
        UIImageView *iv = (UIImageView *)[self.view viewWithTag:100];
        UIImageView *addIv = (UIImageView *)[self.view viewWithTag:102];
        [self takePhoto];
        self.photoBlock = ^(UIImage * _Nonnull image) {
            dispatch_async(dispatch_get_main_queue(), ^{
                addIv.hidden = YES;
                iv.image = image;
                weakSelf.licenseUrl = [weakSelf uploadImagelicenseUrl:image];
            });
        };
    }
    else if (btn.tag == 111)
    {
        UIImageView *iv = (UIImageView *)[self.view viewWithTag:110];
        UIImageView *addIv = (UIImageView *)[self.view viewWithTag:112];
        [self takePhoto];
        self.photoBlock = ^(UIImage * _Nonnull image) {
            dispatch_async(dispatch_get_main_queue(), ^{
                addIv.hidden = YES;
                iv.image = image;
                weakSelf.authUrl = [weakSelf uploadImagelicenseUrl:image];
            });
        };
    }
}

#pragma mark -- 设置店铺头像
- (void)shopPhoto:(UITapGestureRecognizer *)tap
{
    //隐藏小图片
    UIButton *btn = (UIButton *)[self.view viewWithTag:33];
    UIImageView *iv = (UIImageView *)[self.view viewWithTag:32];
    [self takePhoto];
    __weak __typeof(self) weakSelf = self;
    self.photoBlock = ^(UIImage * _Nonnull image) {
        btn.hidden = YES;
        iv.image = image;
        weakSelf.iconImageUrl = [weakSelf uploadImageLogoUrl:image];
    };
}

#pragma mark -- 设置店铺地区
- (void)areaClick:(UITapGestureRecognizer *)tap
{
    MyhAddressPickerView *pickerView = [MyhAddressPickerView shareInstance];
    [pickerView showBottomView];
    [self.view addSubview:pickerView];
    
    UILabel *label = (UILabel *)[self.view viewWithTag:62];
    pickerView.block = ^(NSString *province,NSString *city,NSString *district)
    {
       // label.text = [NSString stringWithFormat:@"%@%@市%@",province,city,district];
        label.attributedText = [TTKUtil getAtttributeStringWithLineSpace:0 kern:2 and:[NSString stringWithFormat:@"%@%@市%@",province,city,district]];
    };
}

#pragma mark -- 删除图片
- (void)deleteImage:(UIButton *)btn
{
    UIImageView *leftIV = (UIImageView *)[self.view viewWithTag:60];
    UIImageView *rightIV = (UIImageView *)[self.view viewWithTag:61];
    UIImageView *leftDele = (UIImageView *)[self.view viewWithTag:72];
    UIImageView *rightDele = (UIImageView *)[self.view viewWithTag:73];
//    UIButton *deleBtn1 = (UIButton *)[self.view viewWithTag:74];
//    UIButton *deleBtn2 = (UIButton *)[self.view viewWithTag:75];
    UIImageView *takePhoto1 = (UIImageView *)[self.view viewWithTag:65];
    UIImageView *takePhoto2 = (UIImageView *)[self.view viewWithTag:66];
    
    if (btn.tag == 74) {
        //删除第一张图片，隐藏
        btn.hidden = YES;
        leftDele.hidden = YES;
        takePhoto1.hidden = NO;
        leftIV.image = nil;
        self.shopImageUrl = nil;
       // CGRect frame;
        if (![TTKUtil isNil:self.shopImageUrl2]) {
//            frame = rightIV.frame;
//            rightIV.frame = leftIV.frame;
//            leftIV.frame = frame;
        }
        else{
            rightIV.hidden = YES;
            takePhoto2.hidden = YES;
        }
    }
    else if(btn.tag == 75)
    {
        rightIV.image = nil;
        self.shopImageUrl2 = nil;
        btn.hidden = YES;
        rightDele.hidden = YES;
        takePhoto2.hidden = NO;
        if ([TTKUtil isNil:self.shopImageUrl]) {
            btn.hidden = NO;
            rightIV.hidden = YES;
        }
    }
}

#pragma mark -- 设置店铺实景图
- (void)shopRealImage:(UIButton *)btn
{
    UIImageView *leftIV = (UIImageView *)[self.view viewWithTag:60];
    UIImageView *rightIV = (UIImageView *)[self.view viewWithTag:61];
    UIImageView *leftDele = (UIImageView *)[self.view viewWithTag:72];
    UIImageView *rightDele = (UIImageView *)[self.view viewWithTag:73];
    UIButton *deleBtn1 = (UIButton *)[self.view viewWithTag:74];
    UIButton *deleBtn2 = (UIButton *)[self.view viewWithTag:75];
    UIImageView *takePhoto1 = (UIImageView *)[self.view viewWithTag:65];
    UIImageView *takePhoto2 = (UIImageView *)[self.view viewWithTag:66];
     __weak __typeof(self) weakSelf = self;
    if (btn.tag == 70) {
        [self takePhoto];
        self.photoBlock = ^(UIImage * _Nonnull image) {
            leftDele.hidden = NO;
            deleBtn1.hidden = NO;
            takePhoto1.hidden = YES;
            rightIV.hidden = NO; //不再隐藏
            takePhoto2.hidden = NO;
            weakSelf.shopImageUrl = [weakSelf uploadImageshopImageUrl:image];
            leftIV.image = image;
        };
    }else if(btn.tag == 71)
    {
        [self takePhoto];
        self.photoBlock = ^(UIImage * _Nonnull image) {
            dispatch_async(dispatch_get_main_queue(), ^{
                rightDele.hidden = NO;
                deleBtn2.hidden = NO;
                takePhoto2.hidden = YES;
                weakSelf.shopImageUrl2 = [weakSelf uploadImageshopImageUrl2:image];
                 rightIV.image = image;
            });
        };
    }
}

#pragma mark -- 身份证正反面
- (void)shopIDCardImage:(UIButton *)btn
{
    UIImageView *leftIV = (UIImageView *)[self.view viewWithTag:160];
    UIImageView *rightIV = (UIImageView *)[self.view viewWithTag:161];
    UIImageView *leftDele = (UIImageView *)[self.view viewWithTag:172];
    UIImageView *rightDele = (UIImageView *)[self.view viewWithTag:173];
    UIButton *deleBtn1 = (UIButton *)[self.view viewWithTag:174];
    UIButton *deleBtn2 = (UIButton *)[self.view viewWithTag:175];
    UIImageView *takePhoto1 = (UIImageView *)[self.view viewWithTag:165];
    UIImageView *takePhoto2 = (UIImageView *)[self.view viewWithTag:166];
    UILabel *idLabel1 = (UILabel *)[self.view viewWithTag:167];
    UILabel *idLabel2 = (UILabel *)[self.view viewWithTag:168];
    __weak __typeof(self) weakSelf = self;
    if (btn.tag == 170)
    {
        [self takePhoto];
        self.photoBlock = ^(UIImage * _Nonnull image) {
            leftDele.hidden = NO;
            deleBtn1.hidden = NO;
            idLabel1.hidden = YES;
            idLabel2.hidden = NO;
            takePhoto1.hidden = YES;
            leftIV.image = image;
            rightIV.hidden = NO; //不再隐藏
            weakSelf.idCardFront = [weakSelf uploadIdCardFrontUrl:image];
        };
    }
    else if (btn.tag == 171)
    {
        [self takePhoto];
        self.photoBlock = ^(UIImage * _Nonnull image) {
            dispatch_async(dispatch_get_main_queue(), ^{
                rightDele.hidden = NO;
                deleBtn2.hidden = NO;
                idLabel2.hidden = YES;
                takePhoto2.hidden = YES;
                rightIV.image = image;
                weakSelf.idCardBack = [weakSelf uploadIdCardFrontUrl:image];
            });
        };
    }
}

#pragma mark -- 上传图片
- (NSString *)uploadImageUrl:(UIImage *)image
{
    UIImage *imageNew = [TTKUtil imageWithImageSimple:image scaledToSize:CGSizeMake(200, 200)];
    NSData *imageData = UIImageJPEGRepresentation(imageNew, 0.5);
    NSMutableDictionary *dict = [NSMutableDictionary new];
    [dict setValue:imageData forKey:@"file"];
    __weak __typeof(self) weakSelf = self;
    [[HttpRequest currentHttpRequest]uploadWithParams:dict andImageData:imageData block:^(NSString *SamllPhoto) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            weakSelf.indexUrl = [NSString stringWithFormat:@"%@",SamllPhoto];
        });
    }];
     return weakSelf.indexUrl;
}

- (NSData *)imageBackToNSData:(UIImage *)image
{
    NSData *imageData1 = UIImageJPEGRepresentation(image, 0.6);
    NSLog(@"压缩前大小=%.2fMB",(float)imageData1.length/1024.0f/1024.0f);
    UIImage *newImage  = [TTKUtil imageWithOriginalImage:image];
    NSData *imageData2 = UIImageJPEGRepresentation(newImage, 0.6);
    NSLog(@"压缩后大小=%.2fMB",(float)imageData2.length/1024.0f/1024.0f);
    return imageData2;
}

//店铺logo图片
- (NSString *)uploadImageLogoUrl:(UIImage *)image
{
    //UIImage *imageNew = [TTKUtil imageWithImageSimple:image scaledToSize:CGSizeMake(200, 200)];
    NSData *imageData1 = UIImageJPEGRepresentation(image, 0.65);
    NSLog(@"压缩前大小=%.2fMB",(float)imageData1.length/1024.0f/1024.0f);
    UIImage *newImage  = [TTKUtil imageWithOriginalImage:image];
    NSData *imageData2 = UIImageJPEGRepresentation(newImage, 0.65);;
    NSLog(@"压缩后大小=%.2fMB",(float)imageData2.length/1024.0f/1024.0f);
    
    NSMutableDictionary *dict = [NSMutableDictionary new];
    [dict setValue:imageData2 forKey:@"file"];
    __weak __typeof(self) weakSelf = self;
    [[HttpRequest currentHttpRequest]uploadWithParams:dict andImageData:imageData2 block:^(NSString *SamllPhoto) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            weakSelf.iconImageUrl = [NSString stringWithFormat:@"%@",SamllPhoto];
        });
    }];
    return weakSelf.iconImageUrl;
}
//店铺实景图1
- (NSString *)uploadImageshopImageUrl:(UIImage *)image
{
//    UIImage *imageNew = [TTKUtil imageWithImageSimple:image scaledToSize:CGSizeMake(600, 400)];
//    NSData *imageData = UIImageJPEGRepresentation(imageNew, 0.5);
    NSData *imageData = [self imageBackToNSData:image];
    NSMutableDictionary *dict = [NSMutableDictionary new];
    [dict setValue:imageData forKey:@"file"];
    __weak __typeof(self) weakSelf = self;
    [[HttpRequest currentHttpRequest]uploadWithParams:dict andImageData:imageData block:^(NSString *SamllPhoto) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            weakSelf.shopImageUrl = [NSString stringWithFormat:@"%@",SamllPhoto];
        });
    }];
    return weakSelf.shopImageUrl;
}
//店铺实景图2
- (NSString *)uploadImageshopImageUrl2:(UIImage *)image
{
    NSData *imageData = [self imageBackToNSData:image];
    NSMutableDictionary *dict = [NSMutableDictionary new];
    [dict setValue:imageData forKey:@"file"];
    __weak __typeof(self) weakSelf = self;
    [[HttpRequest currentHttpRequest]uploadWithParams:dict andImageData:imageData block:^(NSString *SamllPhoto) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            weakSelf.shopImageUrl2 = [NSString stringWithFormat:@"%@",SamllPhoto];
        });
    }];
    return weakSelf.shopImageUrl2;
}

//微信二维码图片
- (NSString *)uploadImageCodeUrl:(UIImage *)image
{
    NSData *imageData = [self imageBackToNSData:image];
    NSMutableDictionary *dict = [NSMutableDictionary new];
    [dict setValue:imageData forKey:@"file"];
    __weak __typeof(self) weakSelf = self;
    [[HttpRequest currentHttpRequest]uploadWithParams:dict andImageData:imageData block:^(NSString *SamllPhoto) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            weakSelf.codeUrl = [NSString stringWithFormat:@"%@",SamllPhoto];
        });
    }];
    return weakSelf.codeUrl;
}

//营业执照图片
- (NSString *)uploadImagelicenseUrl:(UIImage *)image
{
    NSData *imageData = [self imageBackToNSData:image];
    NSMutableDictionary *dict = [NSMutableDictionary new];
    [dict setValue:imageData forKey:@"file"];
    __weak __typeof(self) weakSelf = self;
    [[HttpRequest currentHttpRequest]uploadWithParams:dict andImageData:imageData block:^(NSString *SamllPhoto) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            weakSelf.licenseUrl = [NSString stringWithFormat:@"%@",SamllPhoto];
        });
    }];
    return weakSelf.licenseUrl;
}
//店铺授权书
- (NSString *)uploadImageAuthUrl:(UIImage *)image
{
//    UIImage *imageNew = [TTKUtil imageWithImageSimple:image scaledToSize:CGSizeMake(400, 600)];
    NSData *imageData = [self imageBackToNSData:image];
    NSMutableDictionary *dict = [NSMutableDictionary new];
    [dict setValue:imageData forKey:@"file"];
    __weak __typeof(self) weakSelf = self;
    [[HttpRequest currentHttpRequest]uploadWithParams:dict andImageData:imageData block:^(NSString *SamllPhoto) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            weakSelf.authUrl = [NSString stringWithFormat:@"%@",SamllPhoto];
        });
    }];
    return weakSelf.authUrl;
}

- (NSString *)uploadIdCardFrontUrl:(UIImage *)image
{
    NSData *imageData = [self imageBackToNSData:image];
    NSMutableDictionary *dict = [NSMutableDictionary new];
    [dict setValue:imageData forKey:@"file"];
    __weak __typeof(self) weakSelf = self;
    [[HttpRequest currentHttpRequest]uploadWithParams:dict andImageData:imageData block:^(NSString *SamllPhoto) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            weakSelf.idCardFront = [NSString stringWithFormat:@"%@",SamllPhoto];
        });
    }];
    return weakSelf.idCardFront;
}

- (NSString *)uploadIdCardBackUrl:(UIImage *)image
{
    NSData *imageData = [self imageBackToNSData:image];
    NSMutableDictionary *dict = [NSMutableDictionary new];
    [dict setValue:imageData forKey:@"file"];
    __weak __typeof(self) weakSelf = self;
    [[HttpRequest currentHttpRequest]uploadWithParams:dict andImageData:imageData block:^(NSString *SamllPhoto) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            weakSelf.idCardBack = [NSString stringWithFormat:@"%@",SamllPhoto];
        });
    }];
    return weakSelf.idCardBack;
}

- (void)deleteIDCardImage:(UIButton*)btn
{
    UIImageView *leftIV = (UIImageView *)[self.view viewWithTag:160];
    UIImageView *rightIV = (UIImageView *)[self.view viewWithTag:161];
    UIImageView *leftDele = (UIImageView *)[self.view viewWithTag:172];
    UIImageView *rightDele = (UIImageView *)[self.view viewWithTag:173];
    UIImageView *takePhoto1 = (UIImageView *)[self.view viewWithTag:165];
    UIImageView *takePhoto2 = (UIImageView *)[self.view viewWithTag:166];
    UILabel *idLabel1 = (UILabel *)[self.view viewWithTag:167];
    UILabel *idLabel2 = (UILabel *)[self.view viewWithTag:168];
    if (btn.tag == 174) {
        //删除第一张图片，隐藏
        btn.hidden = YES;
        idLabel1.hidden = NO;
        leftDele.hidden = YES;
        takePhoto1.hidden = NO;
        leftIV.image = nil;
        self.idCardFront = nil;
      //  CGRect frame;
        if (![TTKUtil isNil:self.idCardBack]) {
//            frame = rightIV.frame;
//            rightIV.frame = leftIV.frame;
//            leftIV.frame = frame;
        }
        else{
            rightIV.hidden = YES;
            idLabel2.hidden = YES;
        }
    }
    else if(btn.tag == 175)
    {
        rightIV.image = nil;
        self.idCardBack = nil;
        btn.hidden = YES;
        idLabel2.hidden = NO;
        rightDele.hidden = YES;
        takePhoto2.hidden = NO;
        if ([TTKUtil isNil:self.idCardFront]) {
            rightIV.hidden = YES;
            idLabel2.hidden = YES;
        }
    }
}

- (void)nextBtn:(UIButton *)btn
{
    NSLog(@"下一步");
    if (self.address.length == 0 || [TTKUtil isNil:self.address]) {
        [self ShowHUDWithMessage:@"地址不能为空"];
        return;
    }
    if (self.province.length == 0 || self.city.length == 0|| self.district.length == 0) {
        [self ShowHUDWithMessage:@"省市区不能为空"];
    }
    if (self.iconImageUrl.length == 0)
    {
        [self ShowHUDWithMessage:@"店铺图片不能为空"];
        return;
    }
    if (self.licenseUrl.length == 0)
    {
        [self ShowHUDWithMessage:@"营业执照图片不能为空"];
        return;
    }
    if (self.telTF.text.length == 0)
    {
        [self ShowHUDWithMessage:@"联系电话不能为空"];
        return;
    }
    if (self.ownNameTF.text.length == 0)
    {
        [self ShowHUDWithMessage:@"店主姓名不能为空"];
        return;
    }
    if (self.codeUrl.length == 0)
    {
        [self ShowHUDWithMessage:@"微信二维码不能为空"];
        return;
    }
    if (self.shopImageUrl.length ==0) {
        [self ShowHUDWithMessage:@"店铺实景图不能为空"];
        return;
    }
    if (self.shopImageUrl2.length == 0)
    {
        [self ShowHUDWithMessage:@"店铺实景图需要两张"];
        return;
    }
    if (self.nameTF.text.length == 0) {
        [self ShowHUDWithMessage:@"店铺名称不能为空"];
        return;
    }
    
    //判断一张还是两张图片
    if (self.shopImageUrl.length > 0 && self.shopImageUrl2.length > 0) {
        self.mainImageUrl = [NSString stringWithFormat:@"%@,%@",self.shopImageUrl,self.shopImageUrl2];
    }
    else
    {
         self.mainImageUrl = [NSString stringWithFormat:@"%@",self.shopImageUrl];
    }
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:self.address forKey:@"address"];
    [dict setValue:self.province forKey:@"province"];
    [dict setValue:self.city forKey:@"city"];
    [dict setValue:self.district forKey:@"district"];
    [dict setValue:[NSNumber numberWithDouble:self.latitude] forKey:@"latitude"]; //纬度
    [dict setValue:[NSNumber numberWithDouble:self.longitude] forKey:@"longitude"];//经度
    [dict setValue:self.licenseUrl forKey:@"licenseImage"];//营业执照
    [dict setValue:self.iconImageUrl forKey:@"logo"];//logo
    [dict setValue:self.telTF.text forKey:@"ownerMobile"];//电话
    [dict setValue:self.ownNameTF.text forKey:@"ownerName"];//店主姓名
    [dict setValue:self.codeUrl forKey:@"sellerWechatQrImage"];//卖家微信二维码
    [dict setValue:self.mainImageUrl forKey:@"shopImage"];//实景图
    [dict setValue:self.nameTF.text forKey:@"shopName"];//店铺名称
    if (![TTKUtil isNil:self.authUrl]) {
        [dict setValue:self.authUrl forKey:@"authImage"];
    }
    if (![TTKUtil isNil:self.idCardFront]) {
        [dict setValue:[NSString stringWithFormat:@"%@,%@",self.idCardFront,self.idCardBack] forKey:@"authIdCardImage"];
    }
    
    [HttpRequest formPostPath:SaveShopInfo params:dict resultBlock:^(id Data, MsgModel  *msgModel) {
        if (msgModel.status == 200) {
            if (self.isFailure) {
                CheckShopViewController *checkVC = [CheckShopViewController new];
                [self.navigationController pushViewController:checkVC animated:YES];
            }
            else{
                CreateAccountController *maintainVC = [CreateAccountController new];
                [self.navigationController pushViewController:maintainVC animated:YES];
            }
        }
    }];
}

#pragma mark -- 下载授权书
- (void)download:(UIButton *)btn
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://a-img.eb56.com/c/authorization/authorization.pdf"]];
    //[self downloadPDF:@"http://a-img.eb56.com/c/authorization/authorization.pdf"];
}
#pragma mark --  tf的检测
- (void)TextFieldChange
{
    NSString *tel = self.telTF.text;
    if (tel.length > 11)
    {
        self.telTF.text = [tel substringToIndex:11];
    }
}

#pragma mark -- 设置label属性
- (void)setLabelAttri:(UILabel *)label andStr:(NSString *)str
{
    label.textColor = titleColor;
    label.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:12];
    label.attributedText = [TTKUtil getAtttributeStringWithLineSpace:0 kern:1 and:str];
}

- (void)leftBtnClick:(UIButton *)btn
{
    [self.navigationController popViewControllerAnimated:YES];
}

@end
